home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Apple Macintosh Developer Technical Support
- **
- ** Program: MacShell
- ** File: doevent.c
- ** Written by: Eric Soldan
- **
- ** Copyright © 1990-1991 Apple Computer, Inc.
- ** All rights reserved.
- */
-
-
-
- /*****************************************************************************/
-
-
-
- #include "MacShell.h" /* Get the MacShell includes/typedefs, etc. */
- #include "MacShellCommon.h" /* Get the stuff in common with rez. */
- #include "MacShell.protos" /* Get the prototypes for MacShell. */
-
- #ifndef __CTLHANDLER__
- #include "CtlHandler.h"
- #endif
-
- #ifndef __DESK__
- #include <Desk.h>
- #endif
-
- #ifndef __DISKINIT__
- #include <DiskInit.h>
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
- #ifndef __TEXTEDITCONTROL__
- #include "TextEditControl.h"
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifdef THINK_C
- #include "Utilities.h"
- #else
- #ifndef __UTILITIES__
- #include <Utilities.h>
- #endif
- #endif
-
-
-
- /*****************************************************************************/
-
-
-
- extern Cursor *gCursorPtr;
-
-
-
- /*****************************************************************************/
- /*****************************************************************************/
-
-
-
- /* Do the right thing for an event. Determine what kind of event it is, and
- ** call the appropriate routines.
- */
-
- #pragma segment Main
- void DoEvent(EventRecord *event)
- {
- WindowPtr window;
- FileRecHndl frHndl;
- Rect contentRct, old, growLimits;
- Point pt;
- long size;
- short part, hDocSize, vDocSize;
- OSErr err;
- char key;
- #if MACSHELL_VERSION
- TEHandle teHndl;
- #endif
-
- switch(event->what) {
-
- case nullEvent:
- DoIdleTasks(event);
- break;
-
- case mouseDown:
- gCursorPtr = nil;
- /* No shortcuts when we recalculate the cursor region. */
-
- part = FindWindow(event->where, &window);
- if (part != inContent) DoSetCursor(&qd.arrow);
-
- switch(part) {
-
- case inContent:
- if (window != FrontWindow()) {
- SelectWindow(window);
- if (IsAppWindow(window)) {
- DoUpdate(window);
- contentRct = GetWindowContentRect(window);
- if (PtInRect(event->where, &contentRct)) DoEvent(event);
- } /* Do first click. */
- } else DoContentClick(window, event);
- break;
-
- case inDrag:
- DragWindow(window, event->where, &qd.screenBits.bounds);
- break; /* Pass screenBits.bounds to get all gDevices. */
-
- case inGoAway:
- if (TrackGoAway(window, event->where)) DisposeOneWindow(window, iClose);
- break;
-
- case inGrow:
- old = GetWindowContentRect(window);
- SetRect(&growLimits, kMinWindowWidth, kMinWindowHeight,
- kMaxWindowWidth, kMaxWindowHeight);
- if (size = GrowWindow(window, event->where, &growLimits)) {
- pt = *(Point *)&size;
- SizeWindow(window, pt.h, pt.v, true);
- DoResizeWindow(window, old.right - old.left, old.bottom - old.top);
- }
- break;
-
- case inMenuBar: /* Process mouse menu command (if any). */
- AdjustMenus();
- DoMenuCommand(MenuSelect(event->where));
- break;
-
- case inSysWindow: /* Let the system handle the mouseDown. */
- SystemClick(event, window);
- break;
-
- case inZoomIn:
- case inZoomOut:
- if (TrackBox(window, event->where, part)) {
- old = GetWindowContentRect(window);
- frHndl = (FileRecHndl)GetWRefCon(window);
- hDocSize = (*frHndl)->fileState.hDocSize;
- vDocSize = (*frHndl)->fileState.vDocSize;
- if ((*frHndl)->fileState.hScroll) hDocSize += 15;
- if ((*frHndl)->fileState.vScroll) vDocSize += 15;
- ZoomToWindowDevice(window, hDocSize, vDocSize, part, true);
- DoResizeWindow(window, old.right - old.left, old.bottom - old.top);
- }
- break;
-
- }
- break;
-
- case activateEvt:
- gCursorPtr = nil;
- /* No shortcuts when we recalculate the cursor region. */
-
- DoActivate((WindowPtr)event->message,
- (event->modifiers & activeFlag));
- break;
-
- case autoKey:
- case keyDown: /* Check for menukey equivalents. */
- key = event->message & charCodeMask;
- if (event->modifiers & cmdKey) { /* Command key down. */
- if (event->what == keyDown) {
- AdjustMenus();
- /* Enable/disable/check menu items properly. */
- DoMenuCommand(MenuKey(key));
- }
- break;
- }
-
- if (!IsAppWindow(window = FrontWindow())) break;
-
- DoContentKey(window, event);
- break;
-
- case diskEvt:
- gCursorPtr = nil;
- /* No shortcuts when we recalculate the cursor region. */
-
- if (HiWord(event->message) != noErr) {
- SetPt(&pt, kDILeft, kDITop);
- err = DIBadMount(pt, event->message);
- }
- break; /* It is not a bad idea to at least call DIBadMount
- ** in response to a diskEvt, so that the user can
- ** format a floppy.
- */
- case kHighLevelEvent:
- gCursorPtr = nil;
- /* No shortcuts when we recalculate the cursor region. */
-
- DoHighLevelEvent(event);
- break;
-
- case kOSEvent:
- gCursorPtr = nil;
- /* No shortcuts when we recalculate the cursor region. */
-
- switch ((event->message >> 24) & 0xFF) {
- /* Must logical and with 0xFF to get only low byte. */
- /* High byte of message. */
-
- case kMouseMovedMessage:
- break;
-
- case kSuspendResumeMessage:
- /* Suspend/resume is also an activate/deactivate. */
- gInBackground = !(event->message & kResumeMask);
- DoActivate(FrontWindow(), !gInBackground);
- break;
- }
- break;
-
- case updateEvt:
- DoUpdate((WindowPtr)event->message);
- break;
-
- }
-
- DoCursor();
- AdjustMenus();
-
- #if MACSHELL_VERSION
- if (teHndl = CTEFindActive(nil)) {
- BeginContent(window = (*teHndl)->inPort);
- CTEIdle();
- EndContent(window);
- }
- #endif
-
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* This is called when a window is activated or deactivated. */
-
- #pragma segment Main
- void DoActivate(WindowPtr window, Boolean becomingActive)
- {
- #pragma unused (becomingActive)
-
- NotifyCancel();
-
- if (IsAppWindow(window)) {
- SetPort(window);
- DoCtlActivate(window);
- DoDrawFrame(window); /* Redraw window scrollbars and growIcon, if any. */
- BeginContent(window);
- DoDrawControls(window, true); /* Redraw content scrollbars. */
- EndContent(window);
- }
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* This is called when an update event is received for a window. First, the
- ** updateRgn is separated into two parts. Part 1 holds the window frame area,
- ** if any. This is the area that might hold the scrollbars, grow icon, and
- ** any other application-specific frame parts. This is drawn first. Once
- ** this is done, the remainder of the updateRgn is drawn. This allows us to
- ** handle all of the frame clipping without using the clipRgn. By freeing up
- ** the clipRgn, we allow the application to use it without having to share.
- */
-
- #pragma segment Main
- void DoUpdate(WindowPtr window)
- {
- WindowPtr oldPort;
- RgnHandle contPart, framePart;
- Point contOrg;
- FileRecHndl frHndl;
-
- GetPort(&oldPort);
- SetPort(window);
-
- if (IsAppWindow(window)) {
-
- DoUpdateSeparate(window, &contPart, &framePart);
-
- if (framePart) { /* Update the document frame, if any. */
-
- CopyRgn(framePart, ((WindowPeek)window)->updateRgn);
- DisposeRgn(framePart);
- BeginUpdate(window);
- DoDrawFrame(window);
- EndUpdate(window);
- }
- if (contPart) { /* Update the rest of the content. */
- CopyRgn(contPart, ((WindowPeek)window)->updateRgn);
- DisposeRgn(contPart);
- BeginUpdate(window);
- GetContentOrigin(window, &contOrg);
- SetOrigin(contOrg.h, contOrg.v);
- frHndl = (FileRecHndl)GetWRefCon(window);
- DoImageDocument(frHndl);
- SetOrigin(0, 0);
- EndUpdate(window);
- }
- }
- }
-
-
-
-